package
{
	import flash.display.MovieClip;

	public class MineObject
	{
		public var name:String;
		public var pos:Vector2;
		public var r:Number;
		public var mc:MovieClip;

		public function MineObject()
		{
			this.name = "mine";
			this.pos = new Vector2(43, 16);
			this.r = Main.getInstance().tiles.xw * 0.333333333333333;
			Main.getInstance().objects.Register(this);
			this.mc = Main.getInstance().gfx.CreateSprite("debugMineMC", NinjaGraphicsSystem.LAYER_OBJECTS);
			this.mc.visible = false;
		}

		public function Destruct():void
		{
			Main.getInstance().gfx.DestroyMC(this.mc);
			this.mc = null;
		}

		public function Init(params:Array):void
		{
			if (params.length == 2)
			{
				this.pos.x = params[0];
				this.pos.y = params[1];
				Main.getInstance().objects.AddToGrid(this);
				Main.getInstance().objects.Moved(this);
				this.mc.scaleX = (this.mc.scaleY = 2 * this.r);
				this.mc.x = this.pos.x;
				this.mc.y = this.pos.y;
				this.mc.gotoAndStop("mine_unexploded");
				this.mc.visible = true;
			}
		}

		public function UnInit():void
		{
			Main.getInstance().objects.RemoveFromGrid(this);
		}

		public function DumpInitData():String
		{
			return "" + this.pos.x + NinjaGame.OBJPARAM_SEPERATION_CHAR + this.pos.y;
		}

		public function IdleAfterDeath():void
		{
			Main.getInstance().objects.RemoveFromGrid(this);
		}

		public function TestVsPlayer(guy):void
		{
			var _local3 = guy.pos;
			var _local2 = this.pos.x - _local3.x;
			var _local1 = this.pos.y - _local3.y;
			if (Math.sqrt((_local2 * _local2) + (_local1 * _local1)) < (this.r + guy.r))
			{
				this.Explode(-_local2, -_local1);
			}
		}

		public function Explode(dx, dy):void
		{
			Main.getInstance().game.KillPlayer(NinjaGame.KILLTYPE_EXPLOSIVE, dx, dy, this.pos.x, this.pos.y, this);
			Main.getInstance().particles.SpawnExplosion(this.pos);
			this.mc.gotoAndStop("mine_exploded");
		}
	}
}